/**
 * @author : cyb1010
 * @date   : 2024-06-04 10:41:35
 * @file   : lodge.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
const int N = 100010;
int __, n, m, incnt[N];
vector<int> g[N];
bitset<1010> frm[1010], UP[1010], bad;

int fa[N][20], dep[N], dfn[N], idx;
vector<int> son[N];
int lca(int x, int y) {
    if (!x || !y) return x | y;
    if (dep[x] < dep[y]) swap(x, y);
    for (int i = 18; ~i; i--)
        if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
    if (x == y) return x;
    for (int i = 18; ~i; i--)
        if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
    return fa[x][0];
}
void build() {
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int x = q.front();
        if (fa[x][0]) son[fa[x][0]].push_back(x);
        q.pop(), dep[x] = dep[fa[x][0]] + 1;
        for (int i = 1; i <= 18; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
        for (int i : g[x]) {
            fa[i][0] = lca(fa[i][0], x);
            if (!--incnt[i]) q.push(i);
        }
        if (n <= 1000) {
            frm[x].set(x);
            for (int i : g[x]) frm[i] |= frm[x];
        }
    }
}
void init(int p) {
    dfn[p] = ++idx;
    if (n <= 1000) {
        UP[p] = UP[fa[p][0]], UP[p].set(p);
        frm[p] ^= UP[p];
    }
    for (int i : son[p]) init(i);
}
bool cmp(int x, int y) { return dfn[x] < dfn[y]; }

vector<int> tmp[N];
bool up[N];
int tfa[N], k, p, q;
ll f[N][5];

void dfs(int p) {
    f[p][0] = f[p][1] = f[p][2] = f[p][3] = f[p][4] = 0;
    if (up[p] || tmp[p].size() > k) {
        if (!bad[p]) f[p][1] = dep[p] - dep[tfa[p]];
        return;
    }
    f[p][0] = 1;
    for (int i : tmp[p]) {
        dfs(i);
        for (int y = k; ~y; y--) {
            f[p][y] = 0;
            for (int z = y - 1; ~z; z--) f[p][y] += f[p][z] * f[i][y - z];
        }
    }
    if (!bad[p]) f[p][1] += dep[p] - dep[tfa[p]];
}
void solve() {
    cin >> k >> p;
    vector<int> o(p);
    for (int &i : o) cin >> i, up[i] = 1;
    if (n <= 1000)
        for (int i : o) bad |= frm[i];
    sort(ALL(o), cmp);
    for (int i = 1; i < p; i++) o.push_back(lca(o[i - 1], o[i]));
    sort(ALL(o), cmp), o.erase(unique(ALL(o)), o.end()), p = o.size();
    for (int i = 1; i < p; i++)
        tmp[tfa[o[i]] = lca(o[i - 1], o[i])].push_back(o[i]);
    dfs(o[0]), cout << f[o[0]][k] << '\n';
    for (int i : o) tmp[i].clear(), up[i] = tfa[i] = 0;
    if (n <= 1000) bad.reset();
}

int main() {
    fo("lodge");
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> q;
    for (int i = 1, x, y; i <= m; i++)
        cin >> x >> y, g[x].push_back(y), incnt[y]++;
    build(), init(1);
    while (q--) solve();
    return 0 ^ __ ^ 0;
}